/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * buscarUsuario2.java
 *
 * Created on 22-abr-2011, 18:06:15
 */

package interfaces;

import GestorUsuarios.TipoUsuario;
import GestorUsuarios.Usuario;
import clinica.ClinicaView;
import clinica.Interfaces;
import java.awt.Component;
import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.sql.SQLException;
import javax.swing.ImageIcon;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import org.jdesktop.application.Action;
import Controlador.*;
import GestorCitas.Cita;
import GestorCitas.EstadoCita;
import GestorClinico.ControlHorario;
import GestorUsuarios.EstadoUsuario;
import GestorUsuarios.PersonalClinica;
import clinica.Interfaz;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

/**
 *
 * @author victor
 */
public class buscarUsuario2 extends javax.swing.JPanel {

    private ClinicaView app;
    private Usuario [] lusuarios;
    private Interfaces anterior;

    public class MyRenderer extends DefaultTableCellRenderer {
        public Component getTableCellRendererComponent(JTable table, Object value,
                                                     boolean isSelected, boolean hasFocus,
                                                     int row, int column) {
            ImageIcon icon = null;
            if(value.equals(TipoUsuario.PACIENTE)) {
                icon = new ImageIcon(getClass().getResource("/interfaces/resources/user-32.png"));
            } else if(value.equals(TipoUsuario.MEDICO)) {
                icon = new ImageIcon(getClass().getResource("/interfaces/resources/Doctor-32.png"));
            } else if(value.equals(TipoUsuario.GESTOR)) {
                icon = new ImageIcon(getClass().getResource("/interfaces/resources/User-32x32.png"));
            } else if(value.equals(TipoUsuario.FARMACEUTICO)) {
                icon = new ImageIcon(getClass().getResource("/interfaces/resources/Farma-32x32.png"));
            } else if(value.equals(TipoUsuario.TECNICOPRUEBAS)) {
                icon = new ImageIcon(getClass().getResource("/interfaces/resources/tecnico-32.png"));
            }

            setIcon(icon);
            setHorizontalAlignment(CENTER);
            return this;
      }
    }

        public class MyRenderer2 extends DefaultTableCellRenderer {
        public Component getTableCellRendererComponent(JTable table, Object value,
                                                     boolean isSelected, boolean hasFocus,
                                                     int row, int column) {
            ImageIcon icon = null;
            if(value.equals(EstadoUsuario.ACTIVO)) {
                icon = new ImageIcon(getClass().getResource("/interfaces/resources/Box-green-32.png"));
            } else if(value.equals(EstadoUsuario.BAJA_TEMPORAL)) {
                icon = new ImageIcon(getClass().getResource("/interfaces/resources/Box-yellow-32.png"));
            } else if(value.equals(EstadoUsuario.BAJA_DEFINITIVA)) {
                icon = new ImageIcon(getClass().getResource("/interfaces/resources/Box-red-32.png"));
            }

            setIcon(icon);
            setHorizontalAlignment(CENTER);
            return this;
      }
    }

    public class SelectionListener implements ListSelectionListener {
	    JTable table;

	    // It is necessary to keep the table since it is not possible
	    // to determine the table from the event's source
	    SelectionListener(JTable table) {
	        this.table = table;
	    }

	    public void valueChanged(ListSelectionEvent e) {
                if(usuarios.getSelectedRow()>=0) {
                    if(lusuarios[usuarios.getSelectedRow()].getTipo()==TipoUsuario.PACIENTE) {
                        activaOpcionesPaciente();
                    } else if(lusuarios[usuarios.getSelectedRow()].getTipo()==TipoUsuario.MEDICO) {
                        activaOpcionesPersonalClinica(true);
                    }
                    else activaOpcionesPersonalClinica(false);

	    }
	}
    }

    /** Creates new form buscarUsuario2 */
    public buscarUsuario2(ClinicaView a) {
        app = a;
        initComponents();
        String[] columnNames = {"Tipo","Nombre y apellidos","DNI","Rol","Estado"};
        modelo = new DefaultTableModel(null, columnNames);
        usuarios.setModel(modelo);
        usuarios.getColumn("Tipo").setCellRenderer(new MyRenderer());
        usuarios.setRowHeight(32);
        usuarios.getColumn("Tipo").setWidth(32);
        usuarios.getColumn("Tipo").setMinWidth(32);
        usuarios.getColumn("Tipo").setMaxWidth(32);

        usuarios.getColumn("Estado").setCellRenderer(new MyRenderer2());
        usuarios.getColumn("Estado").setWidth(32);
        usuarios.getColumn("Estado").setMinWidth(32);
        usuarios.getColumn("Estado").setMaxWidth(32);

        usuarios.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

	SelectionListener listener = new SelectionListener(usuarios);
	usuarios.getSelectionModel().addListSelectionListener(listener);
	usuarios.getColumnModel().getSelectionModel().addListSelectionListener(listener);


    }

    public void desactivaTodasAcciones() {
        btnverdatos.setEnabled(false);
        btnmodificardatos.setEnabled(false);
        btncambiarestado.setEnabled(false);

        btnvercitas.setEnabled(false);
        btnpedircita.setEnabled(false);

        btnverhorario.setEnabled(false);
        btnmodificarhorario.setEnabled(false);

        btncambiarcontrasena.setEnabled(false);
        btn_fichadas.setEnabled(false);
    }

    public void activaOpcionesPaciente() {
        btnverdatos.setEnabled(true);
        btnmodificardatos.setEnabled(true);
        btncambiarestado.setEnabled(true);

        btnvercitas.setEnabled(true);
        btnpedircita.setEnabled(true);

        btnverhorario.setEnabled(false);
        btnmodificarhorario.setEnabled(false);

        btncambiarcontrasena.setEnabled(true);
        btn_fichadas.setEnabled(false);
    }

    public void activaOpcionesPersonalClinica(boolean es_medico) {
        btnverdatos.setEnabled(true);
        btnmodificardatos.setEnabled(true);
        btncambiarestado.setEnabled(true);

        if(es_medico == true)
            btnvercitas.setEnabled(true);
        else
            btnvercitas.setEnabled(false);

        btnpedircita.setEnabled(false);

        btnverhorario.setEnabled(true);
        btnmodificarhorario.setEnabled(true);

        btncambiarcontrasena.setEnabled(true);
        btn_fichadas.setEnabled(true);
    }

    public void rellenaUsuarios(Usuario [] us, Interfaces ant) {
        anterior = ant;
        desactivaTodasAcciones();
        lusuarios = us;
        String[] columnNames = {"Tipo","Nombre y apellidos","DNI","Estado"};
        Object[][] data = new Object[us.length][];
        for(int i=0;i<us.length;i++) {
            data[i] = new Object[4];
            data[i][0] = us[i].getTipo();
            data[i][1] = us[i].getNombre()+" "+us[i].getApellidos();
            data[i][2] = us[i].getDniPasaporte();
            data[i][3] = us[i].getEstado();
        }

        modelo = new DefaultTableModel(data, columnNames) {
            @Override
            public boolean isCellEditable(int row, int col) {
                return false;
            }
        };

        usuarios.setModel(modelo);
        usuarios.getColumn("Tipo").setCellRenderer(new MyRenderer());
        usuarios.setRowHeight(48);
        usuarios.getColumn("Tipo").setWidth(48);
        usuarios.getColumn("Tipo").setMinWidth(48);
        usuarios.getColumn("Tipo").setMaxWidth(48);

        usuarios.getColumn("Estado").setCellRenderer(new MyRenderer2());
        usuarios.getColumn("Estado").setWidth(48);
        usuarios.getColumn("Estado").setMinWidth(48);
        usuarios.getColumn("Estado").setMaxWidth(48);

    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        pnlUsuario = new javax.swing.JPanel();
        btnverdatos = new javax.swing.JButton();
        btnmodificardatos = new javax.swing.JButton();
        btncambiarestado = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        btnvercitas = new javax.swing.JButton();
        btnpedircita = new javax.swing.JButton();
        jPanel6 = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        btnverhorario = new javax.swing.JButton();
        btnmodificarhorario = new javax.swing.JButton();
        btn_fichadas = new javax.swing.JButton();
        jPanel5 = new javax.swing.JPanel();
        btncambiarcontrasena = new javax.swing.JButton();
        jPanel8 = new javax.swing.JPanel();
        jPanel9 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        usuarios = new javax.swing.JTable();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        setName("Form"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance().getContext().getResourceMap(buscarUsuario2.class);
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, resourceMap.getString("jPanel1.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, Interfaz.setFontSize())); // NOI18N
        jPanel1.setName("jPanel1"); // NOI18N

        jTabbedPane1.setFont(Interfaz.setFontSize());
        jTabbedPane1.setName("jTabbedPane1"); // NOI18N

        pnlUsuario.setName("pnlUsuario"); // NOI18N
        pnlUsuario.setLayout(new java.awt.GridLayout(1, 3));

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance().getContext().getActionMap(buscarUsuario2.class, this);
        btnverdatos.setAction(actionMap.get("verDatos")); // NOI18N
        btnverdatos.setFont(Interfaz.setFontSize());
        btnverdatos.setIcon(resourceMap.getIcon("btnverdatos.icon")); // NOI18N
        btnverdatos.setText(resourceMap.getString("btnverdatos.text")); // NOI18N
        btnverdatos.setName("btnverdatos"); // NOI18N
        pnlUsuario.add(btnverdatos);

        btnmodificardatos.setAction(actionMap.get("modificarUsuario")); // NOI18N
        btnmodificardatos.setFont(Interfaz.setFontSize());
        btnmodificardatos.setIcon(resourceMap.getIcon("btnmodificardatos.icon")); // NOI18N
        btnmodificardatos.setText(resourceMap.getString("btnmodificardatos.text")); // NOI18N
        btnmodificardatos.setName("btnmodificardatos"); // NOI18N
        pnlUsuario.add(btnmodificardatos);

        btncambiarestado.setAction(actionMap.get("cambiarEstado")); // NOI18N
        btncambiarestado.setFont(Interfaz.setFontSize());
        btncambiarestado.setIcon(resourceMap.getIcon("btncambiarestado.icon")); // NOI18N
        btncambiarestado.setText(resourceMap.getString("btncambiarestado.text")); // NOI18N
        btncambiarestado.setName("btncambiarestado"); // NOI18N
        pnlUsuario.add(btncambiarestado);

        jTabbedPane1.addTab(resourceMap.getString("pnlUsuario.TabConstraints.tabTitle"), resourceMap.getIcon("pnlUsuario.TabConstraints.tabIcon"), pnlUsuario); // NOI18N

        jPanel3.setName("jPanel3"); // NOI18N
        jPanel3.setLayout(new java.awt.GridLayout(1, 3));

        btnvercitas.setAction(actionMap.get("verCitas")); // NOI18N
        btnvercitas.setFont(Interfaz.setFontSize());
        btnvercitas.setIcon(resourceMap.getIcon("btnvercitas.icon")); // NOI18N
        btnvercitas.setText(resourceMap.getString("btnvercitas.text")); // NOI18N
        btnvercitas.setName("btnvercitas"); // NOI18N
        jPanel3.add(btnvercitas);

        btnpedircita.setAction(actionMap.get("pedirCita")); // NOI18N
        btnpedircita.setFont(Interfaz.setFontSize());
        btnpedircita.setIcon(resourceMap.getIcon("btnpedircita.icon")); // NOI18N
        btnpedircita.setText(resourceMap.getString("btnpedircita.text")); // NOI18N
        btnpedircita.setName("btnpedircita"); // NOI18N
        jPanel3.add(btnpedircita);

        jPanel6.setName("jPanel6"); // NOI18N

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 238, Short.MAX_VALUE)
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 119, Short.MAX_VALUE)
        );

        jPanel3.add(jPanel6);

        jTabbedPane1.addTab(resourceMap.getString("jPanel3.TabConstraints.tabTitle"), resourceMap.getIcon("jPanel3.TabConstraints.tabIcon"), jPanel3); // NOI18N

        jPanel4.setName("jPanel4"); // NOI18N
        jPanel4.setLayout(new java.awt.GridLayout(1, 3));

        btnverhorario.setAction(actionMap.get("verHorario")); // NOI18N
        btnverhorario.setFont(Interfaz.setFontSize());
        btnverhorario.setIcon(resourceMap.getIcon("btnverhorario.icon")); // NOI18N
        btnverhorario.setText(resourceMap.getString("btnverhorario.text")); // NOI18N
        btnverhorario.setName("btnverhorario"); // NOI18N
        jPanel4.add(btnverhorario);

        btnmodificarhorario.setAction(actionMap.get("cambiarHorario")); // NOI18N
        btnmodificarhorario.setFont(Interfaz.setFontSize());
        btnmodificarhorario.setIcon(resourceMap.getIcon("btnmodificarhorario.icon")); // NOI18N
        btnmodificarhorario.setText(resourceMap.getString("btnmodificarhorario.text")); // NOI18N
        btnmodificarhorario.setName("btnmodificarhorario"); // NOI18N
        jPanel4.add(btnmodificarhorario);

        btn_fichadas.setAction(actionMap.get("horasFichadas")); // NOI18N
        btn_fichadas.setFont(Interfaz.setFontSize());
        btn_fichadas.setIcon(resourceMap.getIcon("btn_fichadas.icon")); // NOI18N
        btn_fichadas.setText(resourceMap.getString("btn_fichadas.text")); // NOI18N
        btn_fichadas.setName("btn_fichadas"); // NOI18N
        jPanel4.add(btn_fichadas);

        jTabbedPane1.addTab(resourceMap.getString("jPanel4.TabConstraints.tabTitle"), resourceMap.getIcon("jPanel4.TabConstraints.tabIcon"), jPanel4); // NOI18N

        jPanel5.setFont(resourceMap.getFont("jPanel5.font")); // NOI18N
        jPanel5.setName("jPanel5"); // NOI18N
        jPanel5.setLayout(new java.awt.GridLayout(1, 3));

        btncambiarcontrasena.setAction(actionMap.get("generarPass")); // NOI18N
        btncambiarcontrasena.setFont(Interfaz.setFontSize());
        btncambiarcontrasena.setIcon(resourceMap.getIcon("btncambiarcontrasena.icon")); // NOI18N
        btncambiarcontrasena.setText(resourceMap.getString("btncambiarcontrasena.text")); // NOI18N
        btncambiarcontrasena.setName("btncambiarcontrasena"); // NOI18N
        jPanel5.add(btncambiarcontrasena);

        jPanel8.setName("jPanel8"); // NOI18N

        javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
        jPanel8.setLayout(jPanel8Layout);
        jPanel8Layout.setHorizontalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 238, Short.MAX_VALUE)
        );
        jPanel8Layout.setVerticalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 119, Short.MAX_VALUE)
        );

        jPanel5.add(jPanel8);

        jPanel9.setName("jPanel9"); // NOI18N

        javax.swing.GroupLayout jPanel9Layout = new javax.swing.GroupLayout(jPanel9);
        jPanel9.setLayout(jPanel9Layout);
        jPanel9Layout.setHorizontalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 238, Short.MAX_VALUE)
        );
        jPanel9Layout.setVerticalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 119, Short.MAX_VALUE)
        );

        jPanel5.add(jPanel9);

        jTabbedPane1.addTab(resourceMap.getString("jPanel5.TabConstraints.tabTitle"), resourceMap.getIcon("jPanel5.TabConstraints.tabIcon"), jPanel5); // NOI18N

        jPanel2.setName("jPanel2"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        usuarios.setFont(Interfaz.setFontSize());
        usuarios.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        usuarios.setName("usuarios"); // NOI18N
        usuarios.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                usuariosPropertyChange(evt);
            }
        });
        jScrollPane1.setViewportView(usuarios);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 720, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 158, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jTabbedPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 720, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jButton1.setAction(actionMap.get("aceptar")); // NOI18N
        jButton1.setIcon(resourceMap.getIcon("jButton1.icon")); // NOI18N
        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setName("jButton1"); // NOI18N

        jButton2.setAction(actionMap.get("volver")); // NOI18N
        jButton2.setIcon(resourceMap.getIcon("jButton2.icon")); // NOI18N
        jButton2.setText(resourceMap.getString("jButton2.text")); // NOI18N
        jButton2.setName("jButton2"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButton2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton1)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jButton1)
                    .addComponent(jButton2))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void usuariosPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_usuariosPropertyChange

    }//GEN-LAST:event_usuariosPropertyChange

    public boolean seleccionValida() {
      if(usuarios.getSelectedRow()>=0 && usuarios.getSelectedRow()<usuarios.getRowCount())
          return true;
      else return false;
    }

    @Action
    public void aceptar() {
        app.abrirPrincipalGestor();
    }

    @Action
    public void verDatos() throws SQLException, IOException, ClassNotFoundException {
        if(seleccionValida())
            app.abrirVerDatos(lusuarios[usuarios.getSelectedRow()]);
    }

    @Action
    public void modificarUsuario() throws SQLException, IOException, ClassNotFoundException {
        if(seleccionValida())
            app.abrirModificarUsuario(lusuarios[usuarios.getSelectedRow()]);
    }

    @Action
    public void cambiarEstado() {
        if(seleccionValida())
            app.abrirCambiarEstado(lusuarios[usuarios.getSelectedRow()]);
    }

    @Action
    public void pedirCita() throws SQLException, IOException, ClassNotFoundException, NoSuchAlgorithmException {
        if(seleccionValida())
            app.abrirPedirCita(Interfaces.BUSCAR_USUARIOS2,lusuarios[usuarios.getSelectedRow()]);
    }

    @Action
    public void cambiarHorario() throws SQLException, IOException, ClassNotFoundException, NoSuchAlgorithmException {
        if(seleccionValida())
            app.abrirModificarHorario(lusuarios[usuarios.getSelectedRow()]);
    }

    @Action
    public void verHorario() throws SQLException, IOException, ClassNotFoundException, NoSuchAlgorithmException {
        if(seleccionValida())
            app.abrirVerHorario(lusuarios[usuarios.getSelectedRow()]);
    }

    @Action
    public void generarPass() {
        if(seleccionValida())
            app.abrirGenerarPass(lusuarios[usuarios.getSelectedRow()]);
    }

    @Action
    public void verCitas() throws NoSuchAlgorithmException, IOException, ClassNotFoundException, SQLException {
        if(seleccionValida()) {
            Cita [] c = Controlador.consultarCitas(lusuarios[usuarios.getSelectedRow()].getIdUsuario(), null, null,null);
            if(c!=null)
                app.abrirConsultarCitas(c,Interfaces.BUSCAR_USUARIOS2);
            else app.abrirMensajeError("El paciente no tiene citas.", Interfaces.BUSCAR_USUARIOS2);
        }
    }

    @Action
    public void volver() {
        app.volver(anterior);
    }

    @Action
    public void horasFichadas() throws SQLException, IOException, ClassNotFoundException {
        if(seleccionValida()) {
            ControlHorario[] controlHorario = ((PersonalClinica) lusuarios[usuarios.getSelectedRow()]).getControlHorario(null);
            if(controlHorario == null) {
                app.abrirMensajeError("El trabajador no tiene horas fichadas.", Interfaces.BUSCAR_USUARIOS2);
            } else {
                app.abrirVerFichadas(lusuarios[usuarios.getSelectedRow()], controlHorario);
            }
        }
    }


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btn_fichadas;
    private javax.swing.JButton btncambiarcontrasena;
    private javax.swing.JButton btncambiarestado;
    private javax.swing.JButton btnmodificardatos;
    private javax.swing.JButton btnmodificarhorario;
    private javax.swing.JButton btnpedircita;
    private javax.swing.JButton btnvercitas;
    private javax.swing.JButton btnverdatos;
    private javax.swing.JButton btnverhorario;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JPanel pnlUsuario;
    private javax.swing.JTable usuarios;
    // End of variables declaration//GEN-END:variables

    private TableModel modelo;
}
